import store from '@/store'
import request from '@/utils/request'

/**
 * 登录
 * @param {string} mobile 手机号
 * @param {string} code  验证码
 * @returns Promise
 */

export const loginAPI = (mobile, code) => {
  return request({
    url: '/v1_0/authorizations',
    method: 'POST',
    data: {
      mobile,
      code
    }
  })
}

/**
 *
 * @param {String} mobile 手机号
 * @returns Promise
 */
export const getCodeAPI = (mobile) => {
  return request({
    url: `v1_0/sms/codes/${mobile}`
  })
}

/*
 路径参数： 手动拼接到url上
 请求头参数： headers
 查询(query)参数(get) params
 请求体(bordy)参数(post,patch,deleth) data
*/

//获取用户信息
export const getUserInfoAPI = () => {
  return request({
    url: '/v1_0/user'
    // headers: {
    //     Authorization: store.state.tokenObj.token
    // }
  })
}

/**
 * 获取用户资料
 * @returns
 */
export const getUserProfileAPI = () => {
  return request({
    url: '/v1_0/user/profile'
  })
}

/**
 *修改用户信息，改哪个信息传那个参数
 * @param {*} data {name,gender,birthday...}
 * @returns
 */
export const editUserProfileAPI = (data) => {
  return request({
    url: '/v1_0/user/profile',
    method: 'PATCH',
    data
  })
}

/**
 * 上传头像
 * @param {*} file 图片的文件对象
 * @returns Promise
 */
export const uploadPhoto = (file) => {
  const fm = new FormData()
  fm.append('photo', file)
  return request({
    url: '/v1_0/user/photo',
    method: 'PATCH',
    data:fm
  })
}
